package com.ruoyi.hospital.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.hospital.domain.Hospitals;
import com.ruoyi.hospital.mapper.HospitalsMapper;
import com.ruoyi.hospital.service.HospitalsService;

import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class HospitalsServicelmpl extends ServiceImpl<HospitalsMapper, Hospitals> implements HospitalsService {


    public List<Hospitals> selectHospitalsList(Hospitals hospitals) {
        //判断传递过来的医院名称是否为null


        if (hospitals.getHospitalName() != null && hospitals.getHospitalLevel() != null) {
            //如果不为空值，进行模糊查询，
            QueryWrapper<Hospitals> queryWrapper = new QueryWrapper<>();
            queryWrapper.like("hospital_name", hospitals.getHospitalName())
                    .and(i -> i.like("hospital_level", hospitals.getHospitalLevel()));

            return super.list(queryWrapper);

        }


        if ( hospitals.getHospitalLevel() != null ) {
            //如果不为空值，进行模糊查询，
            QueryWrapper<Hospitals> queryWrapper = new QueryWrapper<>();
            queryWrapper.like("hospital_level", hospitals.getHospitalLevel());

            return super.list(queryWrapper);

        }

        if (hospitals.getHospitalName() != null) {
            //如果不为空值，进行模糊查询，
            QueryWrapper<Hospitals> queryWrapper = new QueryWrapper<>();
            queryWrapper.like("hospital_name", hospitals.getHospitalName());
            return super.list(queryWrapper);

        }

        return super.list();

    }

    @Override
    public boolean savehospitals(Hospitals hospitals) {
        UUID uuid = UUID.randomUUID();
            String hospitalId = uuid.toString();
            hospitals.setHospitalId(hospitalId);

        return super.save(hospitals);
    }
}
